using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Presentation
{
    public partial class Frmmain : Form
    {
        public Frmmain()
        {
            InitializeComponent();
        }

        private void childform(Form childform)
        {
           
            childform.WindowState = FormWindowState.Normal  ;
           // childform.MdiParent = this;
            childform.Show();
        }

        private void btnitemmuonsach_Click(object sender, EventArgs e)
        {
            FrmMuonTra frmmuontra = new FrmMuonTra();
           // frmmuontra.Show();
            childform(frmmuontra);
        }

        private void buttonItem15_Click(object sender, EventArgs e)
        {
            FrmNhanVien frmnhanvien = new FrmNhanVien();
            childform(frmnhanvien);
        }

        private void btnitemdocgia_Click(object sender, EventArgs e)
        {
            FrmDocGia frmdocgia = new FrmDocGia();
            childform(frmdocgia);
        }

        private void btnitemquydinh_Click(object sender, EventArgs e)
        {
            FrmQuyDinh frmquydinh = new FrmQuyDinh();
            childform(frmquydinh);
        }

        private void ribbonBar4_ItemClick(object sender, EventArgs e)
        {
            FrmSach frmsach = new FrmSach();
            childform(frmsach);
        }

        private void buttonItem9_Click(object sender, EventArgs e)
        {
            FrmAnPham frmanpham = new FrmAnPham();
            childform(frmanpham);
        }

        private void buttonItem18_Click(object sender, EventArgs e)
        {
            FrmThanhLySach frmthanhly = new FrmThanhLySach();
            childform(frmthanhly);
        }

        private void buttonItem25_Click(object sender, EventArgs e)
        {
            FrmThongKeDocGia frmtkdocgia = new FrmThongKeDocGia();
            childform(frmtkdocgia);
        }

        private void buttonItem19_Click(object sender, EventArgs e)
        {
            FrmThongKeKho frmthongkekho = new FrmThongKeKho();
            childform(frmthongkekho);
        }

        private void btnitemlapthe_Click(object sender, EventArgs e)
        {
            FrmLapTheDocGia frmlapthedocgia = new FrmLapTheDocGia();
            childform(frmlapthedocgia);
        }

        private void ribbonBar9_ItemClick(object sender, EventArgs e)
        {
            FrmInThe frminthe = new FrmInThe();
            childform(frminthe);

        }

        private void btnitemtimkiem_Click(object sender, EventArgs e)
        {
            FrmTimDocGia frmtimdocgia = new FrmTimDocGia();
            childform(frmtimdocgia);
        }

        private void btnitemgiahan_Click(object sender, EventArgs e)
        {
            FrmGiaHan frmgiahan = new FrmGiaHan();
            childform(frmgiahan);
        }

        private void btnitemthongke_Click(object sender, EventArgs e)
        {
            FrmThongKeMuonTra frmTKMuonTRa = new FrmThongKeMuonTra();
            childform(frmTKMuonTRa);
        }

        private void btnthutien_Click(object sender, EventArgs e)
        {
            FrmThuTienPhat frmthutienphat = new FrmThuTienPhat();
            frmthutienphat.Show();
        }

        private void ribbonBar15_ItemClick(object sender, EventArgs e)
        {
            Process pr = new Process();
            pr.StartInfo.FileName = "calc";
            pr.Start();
            pr.EnableRaisingEvents = true;
        }

        private void buttonItem30_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(Application.StartupPath + "\\HELP.chm");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không tồn tại\n"+ex.ToString());
            }
            
        }

        private void buttonItem31_Click(object sender, EventArgs e)
        {
            FrmLienHe frmlienhe = new FrmLienHe();
            frmlienhe.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblthoigian.Text = DateTime.Now.ToLongTimeString();
        }

        private void buttonItem2_Click(object sender, EventArgs e)
        {
            ResetLogin();

            FrmDangNhap frmdangnhap = new FrmDangNhap();
            frmdangnhap.ShowDialog();

            PhanQuyen();
        }

        private void buttonItem4_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            dr = DevComponents.DotNetBar.MessageBoxEx.Show("Bạn Có Muốn Thoát Không ?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void Frmmain_Load(object sender, EventArgs e)
        {
            FrmDangNhap frm = new FrmDangNhap();
            frm.ShowDialog();

            if (DangNhap.Thoat == 1)
                this.Close();

            PhanQuyen();
        }

        //Reset Tài khoản đang đăng nhập.
        void ResetLogin()
        {
            DangNhap.HoTen = "";
            DangNhap.TenDangNhap = "";
            DangNhap.MatKhau = "";
            DangNhap.BoPhan = "";
        }

        //Phân quyền.
        void PhanQuyen()
        {
            //Đang đăng nhập.
            btnDangNhap.Enabled = false;
            btnDangXuat.Enabled = true;

            DangNhap.DangDangNhap = 1;
            if (DangNhap.BoPhan.Equals("")) //Độc giả.
            {
                DocGia();
                btnDangNhap.Enabled = true;
                btnDangXuat.Enabled = false;
                return;
            }

            if (DangNhap.BoPhan.Equals("BP001"))
            {
                ThuThu();
                return;
            }

            if (DangNhap.BoPhan.Equals("BP002"))
            {
                ThuKho();
                return;
            }

            if (DangNhap.BoPhan.Equals("BP003"))
            {
                ThuQuy();
                return;
            }
            //Là quản trị.
            QuanTri();
        }

        //Hiện-Ẩn tất cả các Tab.
        void HienTab(bool x)
        {
            ribbtabhethong.Enabled = x;
            ribbtabdanhmuc.Enabled = x;
            ribbtabdocgia.Enabled = x;
            ribbtabmuontra.Enabled = x;
            btntracuu.Enabled = x;
            btnthutien.Enabled = x;
            ribbtabtrogiup.Enabled = x;

            panelHeThong.Enabled = x;
            panelDMQL.Enabled = x;
            panelQLDG.Enabled = x;
            panelQLMT.Enabled = x;

            ////Hệ thống.
            //btnitemnhanvien
            //btnitemdocgia
            //btnitemquydinh
            ////------------------
            ////Danh mục quản lý.
            //btndmqlsach
            //btndmqlanpham
            //btndmqlthanhly
            //btndmqlthongke
            ////------------------
            ////Quản lý độc giả.
            //btnitemlapthe
            //btniteminthe
            //btnitemtimkiem
            //btnitemthongkedocgia
            ////------------------
            ////Quản lý mượn trả.
            //btnitemmuonsach
            //btnitemgiahan
            //btnitemthongke
        }

        //Độc giả.
        void DocGia()
        {
            HienTab(false);
            btntracuu.Enabled = true;
            ribbtabtrogiup.Enabled = true;
        }

        //Thủ quỹ.
        void ThuQuy()
        {
            DocGia();
            btnthutien.Enabled = true;
        }

        //Thủ kho.
        void ThuKho()
        {
            DocGia();
            ribbtabdanhmuc.Enabled = true;
            panelDMQL.Enabled = true;
        }

        //Thủ thư.
        void ThuThu()
        {
            DocGia();
            ribbtabdocgia.Enabled = true;
            ribbtabmuontra.Enabled = true;
            panelQLDG.Enabled = true;
            panelQLMT.Enabled = true;
        }

        //Quản trị.
        void QuanTri()
        {
            HienTab(true);
            panelHeThong.Enabled = true;
            panelDMQL.Enabled = true;
            panelQLDG.Enabled = true;
            panelQLMT.Enabled = true;
        }

        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            HienTab(false);
            ribbtabtrogiup.Enabled = true;
            btntracuu.Enabled = true;

            btnDangNhap.Enabled = true;
            btnDangXuat.Enabled = false;
            ResetLogin(); //Xóa rỗng thông tin tài khoản đang đăng nhập.
            DangNhap.DangDangNhap = 0;
        }

        private void Frmmain_MdiChildActivate(object sender, EventArgs e)
        {
            MessageBox.Show("Huy");
        }
    }
}